Overview
This standalone script fetches all NSE indices (NIFTY 50, NIFTY BANK, NIFTY IT, etc.) with live market data including OHLC, LTP, volume, and 52-week highs/lows.Why Standalone?
- Different Data Structure: Indices have different fields compared to stocks
- Separate Use Case: Used for market breadth analysis and index tracking
- Independent Updates: May need to be run at different frequencies than stock data
- Specialized Filtering: Requires specific parameter combinations (
Inst: IDX,Exch: IDX)
What It Fetches
The script retrieves real-time and historical data for NSE indices:Market Data Fields
- Live Data: Open, High, Low, LTP (Last Traded Price)
- Price Changes: Absolute change (Chng) and percentage change (PChng)
- Volume: Today’s cumulative volume (
Min1TotalVolPrevCandle) - 52-Week Range: 52-week high and low values
Metadata Fields
- Symbol (e.g.,
NIFTY 50,NIFTY BANK) - Display Symbol
- Index ID (Sid)
- Exchange and Segment
- Instrument Type
Output Files
Contains array of index objects with live market data. Saved in the current working directory.
API Reference
fetch_all_indices()
Fetches all NSE indices from the ScanX Pro API with live market data.
This function takes no parameters.
bool
Trueif fetch was successfulFalseif API error or critical failure
Min1TotalVolPrevCandle to capture today’s cumulative volume and handles negative overflow values:
- 15-second timeout for API requests
- Checks HTTP status code (expects 200)
- Validates response structure
- Prints informative error messages
When to Run Manually
Market Hours
Market Hours
Run during market hours to get live index movements and volume data.
End of Day
End of Day
Run after market close to capture final closing values for all indices.
New Index Addition
New Index Addition
When NSE launches a new index that you want to track.
Market Breadth Analysis
Market Breadth Analysis
Before running analysis scripts that need current index levels.
Usage
Source Code
Dependencies
requests: HTTP library for API callsjson: JSON serialization/deserializationpipeline_utils: Shared utilities module- Uses
get_headers()for randomized user-agent headers
- Uses
This script uses
get_headers() from pipeline_utils.py for better request handling with user-agent rotation.Integration Notes
While this is a standalone script, the output can be used by:- Market breadth analysis tools
- Index correlation studies
- Sector rotation strategies
- Portfolio benchmarking